package it.nard.sourceframes;

import it.nard.constant.Constant;
import it.nard.controller.BasicController;
import it.nard.controller.LatteInEntrataController;
import it.nard.controller.MainController;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import javax.swing.BorderFactory;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.ListSelectionModel;
import javax.swing.border.TitledBorder;
import javax.swing.table.DefaultTableModel;

import org.dyno.visual.swing.layouts.Bilateral;
import org.dyno.visual.swing.layouts.Constraints;
import org.dyno.visual.swing.layouts.GroupLayout;
import org.dyno.visual.swing.layouts.Leading;
import org.dyno.visual.swing.layouts.Trailing;
import org.jdesktop.swingx.JXTable;

//VS4E -- DO NOT REMOVE THIS LINE!
public class AllevatoriPnl extends JPanel {

	private static final long serialVersionUID = 1L;
	private JPanel jPanel0;
	private JLabel jLabel0;
	private JTextField jTextField0;
	private JTextField jTextField1;
	private JLabel jLabel1;
	private JLabel jLabel2;
	private JTextField jTextField2;
	private JLabel jLabel3;
	private JComboBox jComboBox0;
	private JLabel jLabel4;
	private JTextArea jTextArea0;
	private JScrollPane jScrollPane0;
	private JButton jButton0;
	private JButton jButton1;
	private JXTable jTable0;
	private JScrollPane jScrollPane1;
	private JButton jButton2;
	private JPanel jPanel1;
	private JButton jButton4;
	private JLabel jLabel5;
	private JTextField jTextField3;
	private JButton jButton3;
	private static final String PREFERRED_LOOK_AND_FEEL = "com.sun.java.swing.plaf.windows.WindowsLookAndFeel";
	
	private BasicController controller;
	
	public AllevatoriPnl() {
		initComponents();
	}

	
	public AllevatoriPnl(BasicController basicController){
		initComponents();
		this.controller = basicController;
	}
	private void initComponents() {
		setLayout(new GroupLayout());
		add(getJPanel0(), new Constraints(new Leading(9, 787, 10, 10), new Leading(12, 187, 10, 10)));
		add(getJPanel1(), new Constraints(new Leading(11, 10, 10), new Leading(202, 392, 10, 10)));
		setSize(800, 600);
	}

	private JButton getJButton3() {
		if (jButton3 == null) {
			jButton3 = new JButton();
			jButton3.setText("Anteprima di Stampa");
			jButton3.addActionListener(new ActionListener() {
	
				public void actionPerformed(ActionEvent event) {
					jButton3ActionActionPerformed(event);
				}
			});
		}
		return jButton3;
	}

	public JTextField getJTextField3() {
		if (jTextField3 == null) {
			jTextField3 = new JTextField();
		}
		return jTextField3;
	}

	private JLabel getJLabel5() {
		if (jLabel5 == null) {
			jLabel5 = new JLabel();
			jLabel5.setText("Trova");
		}
		return jLabel5;
	}

	private JButton getJButton4() {
		if (jButton4 == null) {
			jButton4 = new JButton();
			jButton4.setText("Annulla");
			jButton4.addActionListener(new ActionListener() {
	
				public void actionPerformed(ActionEvent event) {
					jButton4ActionActionPerformed(event);
				}
			});
		}
		return jButton4;
	}

	private JPanel getJPanel1() {
		if (jPanel1 == null) {
			jPanel1 = new JPanel();
			jPanel1.setBorder(BorderFactory.createTitledBorder(null, "Lista Allevatori", TitledBorder.LEADING, TitledBorder.DEFAULT_POSITION, null, null));
			jPanel1.setLayout(new GroupLayout());
			jPanel1.add(getJButton2(), new Constraints(new Trailing(12, 200, 452, 521), new Leading(9, 12, 12)));
			jPanel1.add(getJScrollPane1(), new Constraints(new Leading(6, 756, 10, 10), new Bilateral(36, 0, 27)));
			jPanel1.add(getJLabel5(), new Constraints(new Leading(8, 97, 10, 10), new Leading(13, 33, 393)));
			jPanel1.add(getJTextField3(), new Constraints(new Leading(101, 163, 10, 10), new Leading(10, 33, 393)));
			jPanel1.add(getJButton3(), new Constraints(new Trailing(218, 200, 119, 276), new Leading(10, 33, 393)));
		}
		return jPanel1;
	}

	private JButton getJButton2() {
		if (jButton2 == null) {
			jButton2 = new JButton();
			jButton2.setText("Stampa Lista");
			jButton2.addActionListener(new ActionListener() {
	
				public void actionPerformed(ActionEvent event) {
					jButton2ActionActionPerformed(event);
				}
			});
		}
		return jButton2;
	}

	private JScrollPane getJScrollPane1() {
		if (jScrollPane1 == null) {
			jScrollPane1 = new JScrollPane();
			jScrollPane1.setViewportView(getJTable0());
		}
		return jScrollPane1;
	}

	public JXTable getJTable0() {
		if (jTable0 == null) {
			jTable0 = new JXTable();
			
			jTable0.setModel(new DefaultTableModel(new String[][] { }, new String[] { "Nome Allev.", "Codice Az.", "Numero Identif.", "Cisterna" }) {
				private static final long serialVersionUID = 1L;
				Class<?>[] types = new Class<?>[] { String.class, String.class, String.class, String.class };
	
				public Class<?> getColumnClass(int columnIndex) {
					return types[columnIndex];
				}
				public boolean isCellEditable (int row, int column){
					return false;
				}
			});
			jTable0.addMouseListener(new MouseAdapter() {
	
				public void mouseClicked(MouseEvent event) {
					jTable0MouseMouseClicked(event);
				}
			});
		}
		return jTable0;
	}

	private JPanel getJPanel0() {
		if (jPanel0 == null) {
			jPanel0 = new JPanel();
			jPanel0.setBorder(BorderFactory.createTitledBorder(null, "Allevatore", TitledBorder.LEADING, TitledBorder.DEFAULT_POSITION, null, null));
			jPanel0.setLayout(new GroupLayout());
			jPanel0.add(getJLabel0(), new Constraints(new Leading(8, 134, 12, 12), new Leading(7, 18, 12, 12)));
			jPanel0.add(getJTextField0(), new Constraints(new Leading(134, 239, 10, 10), new Leading(6, 12, 12)));
			jPanel0.add(getJTextField2(), new Constraints(new Leading(134, 239, 12, 12), new Leading(34, 10, 10)));
			jPanel0.add(getJLabel2(), new Constraints(new Leading(8, 134, 12, 12), new Leading(37, 18, 12, 12)));
			jPanel0.add(getJLabel4(), new Constraints(new Leading(8, 134, 12, 12), new Leading(66, 18, 12, 12)));
			jPanel0.add(getJScrollPane0(), new Constraints(new Leading(134, 625, 10, 10), new Leading(66, 65, 12, 12)));
			jPanel0.add(getJLabel1(), new Constraints(new Leading(389, 134, 12, 12), new Leading(6, 18, 12, 12)));
			jPanel0.add(getJTextField1(), new Constraints(new Leading(517, 239, 10, 10), new Leading(5, 12, 12)));
			jPanel0.add(getJComboBox0(), new Constraints(new Leading(517, 238, 12, 12), new Leading(30, 12, 12)));
			jPanel0.add(getJButton0(), new Constraints(new Leading(134, 207, 12, 12), new Leading(137, 12, 12)));
			jPanel0.add(getJButton4(), new Constraints(new Leading(344, 200, 10, 10), new Leading(137, 12, 12)));
			jPanel0.add(getJButton1(), new Constraints(new Leading(548, 200, 10, 10), new Leading(137, 12, 12)));
			jPanel0.add(getJLabel3(), new Constraints(new Leading(389, 134, 12, 12), new Leading(30, 18, 12, 12)));
		}
		return jPanel0;
	}

	public JButton getJButton1() {
		if (jButton1 == null) {
			jButton1 = new JButton();
			jButton1.setText("Elimina");
			jButton1.addActionListener(new ActionListener() {
	
				public void actionPerformed(ActionEvent event) {
					jButton1ActionActionPerformed(event);
				}
			});
		}
		return jButton1;
	}

	public JButton getJButton0() {
		if (jButton0 == null) {
			jButton0 = new JButton();
			jButton0.setText("Inserisci");
			jButton0.addActionListener(new ActionListener() {
	
				public void actionPerformed(ActionEvent event) {
					jButton0ActionActionPerformed(event);
				}
			});
		}
		return jButton0;
	}

	private JScrollPane getJScrollPane0() {
		if (jScrollPane0 == null) {
			jScrollPane0 = new JScrollPane();
			jScrollPane0.setViewportView(getJTextArea0());
		}
		return jScrollPane0;
	}

	public JTextArea getJTextArea0() {
		if (jTextArea0 == null) {
			jTextArea0 = new JTextArea();
		}
		return jTextArea0;
	}

	private JLabel getJLabel4() {
		if (jLabel4 == null) {
			jLabel4 = new JLabel();
			jLabel4.setText("Note");
		}
		return jLabel4;
	}

	public JComboBox getJComboBox0() {
		if (jComboBox0 == null) {
			jComboBox0 = new JComboBox();
			jComboBox0.setModel(new DefaultComboBoxModel(Constant.CISTERNE));
			jComboBox0.setDoubleBuffered(false);
			jComboBox0.setBorder(null);
		}
		return jComboBox0;
	}

	private JLabel getJLabel3() {
		if (jLabel3 == null) {
			jLabel3 = new JLabel();
			jLabel3.setText("Cisterna");
		}
		return jLabel3;
	}

	public JTextField getJTextField2() {
		if (jTextField2 == null) {
			jTextField2 = new JTextField();
		}
		return jTextField2;
	}

	private JLabel getJLabel2() {
		if (jLabel2 == null) {
			jLabel2 = new JLabel();
			jLabel2.setText("Numero Identificativo");
		}
		return jLabel2;
	}

	private JLabel getJLabel1() {
		if (jLabel1 == null) {
			jLabel1 = new JLabel();
			jLabel1.setText("Codice Aziendale");
		}
		return jLabel1;
	}

	public JTextField getJTextField1() {
		if (jTextField1 == null) {
			jTextField1 = new JTextField();
		}
		return jTextField1;
	}

	public JTextField getJTextField0() {
		if (jTextField0 == null) {
			jTextField0 = new JTextField();
		}
		return jTextField0;
	}

	private JLabel getJLabel0() {
		if (jLabel0 == null) {
			jLabel0 = new JLabel();
			jLabel0.setText("Nome Allevatore");
		}
		return jLabel0;
	}

	private void jButton0ActionActionPerformed(ActionEvent event) {
		
		
	
			controller.insert();
		
			
		
		
	}

	private void jButton1ActionActionPerformed(ActionEvent event) {
	
		
			controller.delete();
		
	}

	

	private void jTable0MouseMouseClicked(MouseEvent event) {
		controller.select(event);
	}

	private void jButton4ActionActionPerformed(ActionEvent event) {
		
		controller.annulla();
	}

	private void jButton2ActionActionPerformed(ActionEvent event) {
		controller.print(true);
	}

	private void jButton3ActionActionPerformed(ActionEvent event) {
		controller.print(false);
	}

	
	
	
	

}
